<%@ page import="com.gpay.erp.core.system.bean.SysUser" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<script src="<%=request.getContextPath() %>/resources/js/purchase/purchaseManage.js"
        type="text/javascript"></script>
<script src="<%=request.getContextPath() %>/resources/js/purchase/applicationS.js"
        type="text/javascript"></script>
<script src="<%=request.getContextPath() %>/resources/js/purchase/applicationAdd.js"
        type="text/javascript"></script>
<script>
    $(function () {
        $('#totalAmount').numberbox({
               precision:2,groupSeparator:',',decimalSeparator:'.',
            formatter: function (value) {
                return formatNum(value);
            }
        })
        $('#totalWeight').numberbox({
            precision:6,
            formatter: function (value) {
                value = Math.round(parseFloat(value) * Math.pow(10, 6))/Math.pow(10, 6)
                return formatWeight(value);
            }
        })
        $('#taxGoodsAmount').numberbox({
               precision:2,groupSeparator:',',decimalSeparator:'.',
            formatter: function (value) {
                return formatNum(value);
            }
        })
        $('#taxAmount').numberbox({
               precision:2,groupSeparator:',',decimalSeparator:'.',
            formatter: function (value) {
                return formatNum(value);
            }
        })

        var applicationId = $("#applicationId").text();
        if (applicationId) {
            $('#memberNoDiv').html("<label>供应商代码:</label><input id='memberNo' name='f_providerid' data-options='required:true' readonly style='width:90px' />");
            $('#userNameDiv').html("<label>签约人:</label><input id='userName' name='userName' style='width:90px' readonly data-options='editable:false'/>");
            $('#userIdDiv').html("<label>签约人id:</label><input id='userName' name='f_userid' style='width:90px' data-options='editable:false'/>");
            $("#submitFunction").click(function () {
                changeStatus("/purchase/saveCommitApplicationSub.html", applicationId, 2, refreshApplicationPage);
            });
            $("#cancelSubmitFunction").click(function () {
                changeStatus("/purchase/saveCommitApplicationSub.html", applicationId, 1, refreshApplicationPage);
            });
            $("#cancelFunction").click(function () {
                changeStatus("/purchase/saveCommitApplicationSub.html", applicationId, 0, refreshApplicationPage);
            });
            //获取子项列表
            $.ajax({
                type: "post",
                data: {'id': applicationId},
                dataType: "json",
                url: getContextPath() + "/purchase/selectApplicationSub.html",
                before: function () {
                    parent.$.messager.progress({
                        title: '提示',
                        text: '数据处理中，请稍后....'
                    });
                },
                success: function (data) {
                    parent.$.messager.progress('close');
                    if (data && isSuccess(data.result)) {
                        refreshApplicationPage(data);
                        //修改保存按钮
                        $('#editFunction').click(function () {
                            var isValid = showValidteMessage(validateTopSubs(true)) && showValidteMessage(validateBottomSubs(prepareApplicationSubmitPostData(true).applicationSubList));
                            if (isValid) {
                                postAjax("/purchase/saveUpdateApplicationSub.html", JSON.stringify(prepareApplicationSubmitRealPostData(true)),
                                        getApplicationDetail, {async: false});
                            } else {
                                return isValid;
                            }
                        });
                    } else {
                        commonError(data.result, data.message);
                    }
                },
                timeout: 1000,
                error: function (result) {
//			internalError();
                    templateInternalError(result.responseText);
                    parent.$.messager.progress('close');
                }
            });
        } else {
            initComboDataGrid("/suppliersController/selectList.html", $("#memberNo"), getSupplierComboGridOptions());
            initComboDataGrid("/sysUserController/selectUser.html", $('#userName'), userComboGridOptions());
            initDataGridNoPager($('#subItem'), getSubOptions());
            $('#addFunction').click(function () {
                var isValid = showValidteMessage(validateTopSubs()) && showValidteMessage(validateBottomSubs(prepareApplicationSubmitPostData().applicationSubList));
                if (isValid) {
                    postAjax("/purchase/saveApplicationSub.html", JSON.stringify(prepareApplicationSubmitRealPostData()),
                            getApplicationDetail, {async: false});
                } else {
                    return isValid;
                }
            });
            //新增顶部细节
            $('#contractDate').datebox({
                required: true,
                editable: false
            });
            $('#contractDate').datebox("setValue", myformatter(new Date()));
            $('#status').val('新增');
            add();
            calculateToTop();
        }


    });

</script>
<var hidden="hidden" id="applicationId">${applicationId}</var>
<div class="easyui-layout" data-options="fit : true,border : false">
    <div data-options="region:'north',title:'采购申请',border : false" style="height: 140px; overflow: hidden;">
        <form id="searchForm-small">
            <div class="mLeft60">
                <div class="mTop10 line-handsome">
                    <div class="fLeft label-handsome ">
                        <label>采购申请号:</label>
                        <input id="applicationNumber" name="applicationNumber" readonly>
                        </input>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>申请状态:</label>
                        <input id="status" name="status" class="easyui-input" readonly/>
                    </div>
                    <div class="fLeft label-handsome" id="memberNoDiv">
                        <label class="redSharp">* 供应商代码:</label>
                        <select id="memberNo" name="f_providerid" data-options="required:true" style="width:90px">
                        </select>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>供应商名称:</label>
                        <input id="providerName" name="providerName" class="easyui-input" readonly/>
                    </div>
                </div>
                <div class="mTop10 line-handsome">
                    <div class="fLeft label-handsome ">
                        <label>供应商合同号:</label>
                        <input id="providerContract" name="providerContract">
                        </input>
                    </div>
                    <div class="fLeft label-handsome" id="userNameDiv">
                        <label class="redSharp">* 签约人:</label>
                        <select id="userName" name="f_userid" style="width:90px"
                                data-options="editable:false">
                        </select>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>所属部门:</label>
                        <input id="signDept" name="signDept" class="easyui-input" readonly
                               data-options="editable:false"/>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>制单人:</label>
                        <input id="documentMaker" name="documentMaker" class="easyui-input" readonly
                               value="<%=((SysUser)session.getAttribute("loginUser")).getUserName()%>"/>
                    </div>
                </div>
                <div class="mTop10 line-handsome">
                    <div class="fLeft label-handsome ">
                        <label>签约日期:</label>
                        <input id="contractDate" type="text" name="contractDate" class="easyui-datebox"
                               required="required" style="width:90px"/>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>备注:</label>
                        <input id="remark" name="remark" class="easyui-input"/>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>总金额:</label>
                        <input id="totalAmount" name="totalAmount" readonly/>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>总重量:</label>
                        <input id="totalWeight" name="totalWeight" class="easyui-input" readonly/>
                    </div>
                </div>
                <div class="mTop10 line-handsome">
                    <div class="fLeft label-handsome ">
                        <label>含税货款金额:</label>
                        <input id="taxGoodsAmount" name="taxGoodsAmount" class="easyui-input" readonly/>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>税额:</label>
                        <input id="taxAmount" name="taxAmount" class="easyui-input" readonly/>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>采购合同号:</label>
                        <input id="contractCode" name="contractCode" class="easyui-input" readonly/>
                    </div>
                    <div hidden="hidden" id="userIdDiv">

                    </div>

                </div>
            </div>
        </form>
    </div>
    <div data-options="region:'center',border : false,title:'采购申请子项列表'">
        <table id="subItem"></table>
    </div>
</div>